package com.example.designpatterns.prototype;

import java.util.ArrayList;

public class Prototype implements Cloneable {

    public String year;

    public Address address;

    public ArrayList list = new ArrayList();

    public Prototype(String year, Address address, ArrayList list) {
        this.year = year;
        this.address = address;
        this.list = list;
    }

    public Prototype clone() {
        Prototype prototype = null;
        try {
            prototype = (Prototype) super.clone();
            //引用类型如果不指定拷贝方法，则与复制对象与原对象共享同一引用地址
            prototype.list = (ArrayList) this.list.clone();
            prototype.address = this.address.clone();
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }
        return prototype;
    }

    public String getYear() {
        return year;
    }

    public void setYear(String year) {
        this.year = year;
    }

    public Address getAddress() {
        return address;
    }

    public void setAddress(Address address) {
        this.address = address;
    }

    public ArrayList getList() {
        return list;
    }

    public void setList(ArrayList list) {
        this.list = list;
    }
}
